package com.gwf.web;

//import com.gwf.RestCompamyService;
import com.gwf.pojo.User;
import com.gwf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Date;
import java.util.UUID;

/**
 * 入口
 */
@RestController
@RequestMapping(value = "/api")
public class ComRestController {
    //@Autowired
    //private RestCompamyService restCompamyService;

    @Autowired
    private UserService userService;

    //@GetMapping("/get/data")
    //@ResponseBody
    //public ResponseEntity getUser(@RequestParam(name = "id", defaultValue = "") String id) {
    //    System.out.println("Get data:" + id);
    //    return new ResponseEntity(restCompamyService.searchByQuery(), HttpStatus.OK);
    //}

    @GetMapping("/get/user")
    @ResponseBody
    public ResponseEntity get(@RequestParam(name = "id", defaultValue = "") String id) {
        System.out.println("Get user:" + id);
        return new ResponseEntity(userService.search("ab"), HttpStatus.OK);
    }

    //@PostMapping("/add/data")
    //@ResponseBody
    //public ResponseEntity add(
    //        @RequestParam(name = "title") String title,
    //        @RequestParam(name = "author") String author,
    //        @RequestParam(name = "word_count") int wordCount,
    //        @RequestParam(name = "publish_date")
    //        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date publishDate
    //) {
    //    try {
    //        restCompamyService.add();
    //        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
    //        System.out.println("add data: " + uuid);
    //        return new ResponseEntity(uuid, HttpStatus.OK);
    //    } catch (IOException e) {
    //        e.printStackTrace();
    //        return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
    //    }
    //}

    @PostMapping("/add/user")
    @ResponseBody
    public ResponseEntity addUser(@RequestBody User user) {
        userService.insert(user);
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        System.out.println("add user: " + uuid);
        return new ResponseEntity(uuid, HttpStatus.OK);
    }

    //@PostMapping("/user")
    //public boolean createUser(@RequestBody User user) {
    //    return userService.insert(user);
    //}
    //
    //
    //@GetMapping("/user/searchContent")
    //public List<User> search(@RequestParam(value = "searchContent") String searchContent) {
    //	return userService.search(searchContent);
    //}
    //
    //@GetMapping("/user")
    //public List<User> searchUser(@RequestParam(value = "pageNumber") Integer pageNumber,
    //                             @RequestParam(value = "pageSize", required = false) Integer pageSize,
    //                             @RequestParam(value = "searchContent") String searchContent) {
    //    return userService.searchUser(pageNumber, pageSize, searchContent);
    //}
    //
    //
    //@GetMapping("/user2")
    //public List<User> searchUserByWeight(@RequestParam(value = "searchContent") String searchContent) {
    // return userService.searchUserByWeight(searchContent);
    //}


}
